1. Field of the Invention
The present invention relates to a microcomputer with a timer built therein for measuring the interval of a capture signal.
2. Description of the Related Art
A microcomputer has input ports, a memory, a CPU, etc. Various functions can be realized by operation-controlling these circuits by software. Therefore, the microcomputer is used in a wide range of applications such as operation control on home appliances, vehicle engine control, etc.
Also the microcomputer has a timer built therein for controlling timings provided to operate its functions. As the timer circuit built in the microcomputer, there is known, for example, a capture timer (or called “input timer”).
The capture timer has the function of measuring the interval of occurrence of an external input signal. When a change in the voltage level of the external input signal (capture signal),is detected in a state in which a timer counter is being operated, the value of the timer counter is fetched into a timer register. Computing processing is performed using the timer register value and the timer register value updated according to a change in the voltage level of a next-generated external input signal, thereby making it possible to measure the interval of occurrence of the corresponding external input signal.
FIG. 7 is a configurational diagram of a conventional capture timer. The capture timer includes a timer counter 101, a timer register 102, an edge detection circuit 103, and an interrupt register 104 used as a status register. Incidentally, the edge detection circuit 103 is capable of performing three types of detections such as detection of the falling edge, detection of the rising edge and detection of both rising and falling edges. The capture timer 100 is provided with a register for controlling start/stop of the timer counter 101 in accordance with an operation given from a CPU, and a register used as a status register, which indicates the presence or absence of occurrence of OVF of the timer counter (not shown in the figure).
FIG. 8 is a diagram for describing the operation of the capture timer 100. When an external input signal (CAP input) is inputted to the capture timer 100 while the timer counter 101 is in operation, the edge detection circuit 103 detects a change in the voltage level of the external input signal. On the basis of its detected signal, a timer counter value is fetched into the timer register 102 and at the same time an interrupt request signal is generated.
FIG. 9 shows detailed timing for the operation of the capture timer shown in FIG. 8. The CPU outputs a read signal to the capture timer 100 to process the value of the timer register 102. The capture timer 100 outputs the value of the timer register 102 to a bus on the basis of the read signal issued from the CPU.
Incidentally, even when the timing provided to output an edge detection signal and the read signal issued from the CPU are outputted simultaneously as shown in FIG. 10 in such a microcomputer that a CPU clock and a timer counter are operated with the same clock (or synchronous clock), a timer counter value prior to being updated by the edge detection signal is outputted to the corresponding bus, and an incorrect value under which at least a timer register is placed under change, is not outputted to the bus.
The above related art has been disclosed in, for example, Japanese Unexamined Patent Publication No. Hei 7(1995)-260845.
However, in such a microcomputer that the CPU clock and the timer counter clock are perfectly asynchronous, the timer counter 101, the timer register 102 and the edge detection circuit 103 are operated in a timer clock cycle, whereas the read signal from the CPU is generated in a CPU clock cycle. Therefore, there is a possibility that when the timing provided to output an edge detection signal and a signal read from the CPU happen to be outputted in the simultaneous vicinity as shown in FIG. 11, a value lying in the course of a change in timer register value due to the generation of a capture signal will be outputted. With this view, there was a possibility that the interval of a capture signal measured based on this value would be a false one.